﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

using Fusion;

namespace Fusion.Interface
{
	public class CounterLabel : Control
	{
		public int min = 0;
		public int max = 1024;
		public int value = 0;

		public string text;
		public SpriteFont font;
		public Color textColor;

		Vector2 offset;
		float fontScale;

		ChangerLabel changer;


		#region Events

		public VoidDelegate ValueChanged;

		void Down()
		{
			value--;
			if( value < min )
				value = min;

			if( ValueChanged != null )
				ValueChanged();
		}

		void Up()
		{
			value++;
			if( value > max )
				value = max;

			if( ValueChanged != null )
				ValueChanged();
		}

		#endregion


		public CounterLabel( Vector2 center, Vector2 Size, string contents,  VoidDelegate ChangeEvent )
		{
			position = center;
			size = Size;

			text = contents;

			ValueChanged += ChangeEvent;

			drawBorder = false;

			font = Engine.Fonts.Get( "Retro" );
			textColor = new Color( 0.16f, 0.88f, 0.92f, 1.0f );

			fontScale = 1;// size.Y / font.MeasureString( "TEST" ).Y;
			offset.X += 8;

			changer = new ChangerLabel( center + new Vector2( (-Size.Y *2), 0 ), new Vector2( size.Y, size.Y ), Down, Up );
		}

		public override void Update()
		{
			changer.Update();
			base.Update();
		}

		public override void Input( Vector2 cursor, bool button )
		{
			changer.Input( cursor, button );
		}

		public override void Draw()
		{
			base.Draw();
			changer.Draw();

			Engine.spriteBatch.DrawString( font, text + " " + value.ToString(), Position + offset, textColor, 0, new Vector2( 0, 0 ), fontScale * Scale, SpriteEffects.None, 0.5f );
		}
	}
}
